/*
 * File:   Elliptic.h
 * Author: jcrada
 *
 * Created on 26 May 2011, 1:00 PM
 */

#ifndef ECB_ELLIPTIC_H
#define	ECB_ELLIPTIC_H

#include "ecb/base/Problem.h"
#include <cmath>

namespace ecb {

    class Elliptic : public Problem {
    protected:
        std::vector<scalar> _powCache;
    public:
        Elliptic(const std::string& id = "Elliptic", const std::string& name = "Elliptic",
                int dimensions = 0, scalar minimum = -5.12, scalar maximum = 5.12,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }
        scalar f(const std::vector<scalar>& x) {
            if (x.size() != _powCache.size()) {
                _powCache = std::vector<scalar > (x.size(), 0);
                for (size_t i = 0; i < x.size(); ++i) {
                    _powCache[i] = std::pow(1e6, i / (x.size() - 1.0));
                }
            }
            scalar result = 0;
            for (size_t i = 0; i < x.size(); ++i) {
                result += _powCache[i] * x[i] * x[i];
            }
            return result;
        }
    };
}


#endif	/* ECB_ELLIPTIC_H */

